package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    List<Long> seleteByDishId(List<Long> ids);

    /**
     *  套餐分页查询
     * @param pageQueryDTO
     * @return
     */
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO pageQueryDTO);

    /**
     * 根据多个id查询套餐信息
     * @param ids
     * @return
     */
    List<Setmeal> seleteByDishIds(List<Long> ids);

    /**
     * 删除套餐
     * @param ids
     */

    void deleteByIds(List<Long> ids);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("SELECT * from setmeal where id = #{id}")
    SetmealVO getById(Long id);

    /**
     * 修改套餐信息
     * @param
     */
    @AutoFill(value = OperationType.UPDATE)
    void updateById(Setmeal setmea);

    /**
     * 修改套餐关联表，插入数据
     * @param setmealDish
     */
    void setmealDishInsert(List<SetmealDish> setmealDish);

    /**
     * 删除套餐关联表，删除数据
     * @param ids
     */
    void setmealDishdeleteByIds(List<Long> ids);

    /**
     * 新增套餐
     * @param setmeal
     */
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into setmeal (category_id, name, price, description, image, create_time, update_time, create_user, update_user,status) " +
            "values " +
            "(#{categoryId},#{name},#{price},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})")
    void setMealInsert(Setmeal setmeal);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);


    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
